package com.fastCms.business.frame.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fastCms.business.frame.constant.CommonConst;
import com.fastCms.business.frame.daos.UserMapper;
import com.fastCms.business.frame.pojo.entity.User;
import com.fastCms.business.frame.service.UserService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * APP用户 服务实现类
 * </p>
 *
 * @author liusq
 * @since 2024-04-28
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public User findByPhone(String phone) {
        LambdaQueryWrapper<User> userQueryWrapper = new LambdaQueryWrapper<User>();
        userQueryWrapper.eq(User::getPhone, phone);
        userQueryWrapper.eq(User::getState, CommonConst.STATE.VALID);
        return this.getOne(userQueryWrapper);
    }

    @Override
    public User findByUsername(String username) {
        LambdaQueryWrapper<User> userQueryWrapper = new LambdaQueryWrapper<User>();
        userQueryWrapper.eq(User::getUsername, username);
        userQueryWrapper.eq(User::getState, CommonConst.STATE.VALID);
        return this.getOne(userQueryWrapper);
    }

    @Override
    public User findById(String userId) {
        User user = this.getById(userId);
        return user;
    }
}
